package com.zy.servlet.panbaidu;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zy.service.HttpLoginService;

public class LoginBaiduPan extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		PrintWriter out = response.getWriter();
		String urlStr = "https://passport.baidu.com/v2/api/?login";
		String apiver = "v3";
		String callback = "	parent.bd__pcbs__m8jbf0";
		String charset = "utf-8";
		String codestring = "";
		String isPhone = "false";
		String loginmerge = "true";
		String logintype = "basicLogin";
		String mem_pass = "on";
		String password = "zhangyue198z9";
		String username = "wanzyly123";
		String ppui_logintime = "19648";
		String tpl = "netdisk";
		String quick_user = "0";
		String safeflg = "0";
		String staticpage = "http://pan.baidu.com/res/static/thirdparty/pass_v3_jump.html";
		String token = "9721b8d8f7d4488dd5f096447dc9e724";
		String tt = "1389364573522";
		String u = "http://pan.baidu.com/";
		String verifycode = "";
		String content = "apiver=" + apiver + "&callback=" + callback
				+ "&charset=" + charset + "&codestring=" + codestring
				+ "&isPhone=" + isPhone + "&loginmerge=" + loginmerge
				+ "&logintype=" + logintype + "&mem_pass=" + mem_pass
				+ "&password=" + password + "&ppui_logintime=" + ppui_logintime
				+ "&quick_user=" + quick_user + "&safeflg=" + safeflg
				+ "&staticpage=" + staticpage + "&token=" + token + "&tpl="
				+ tpl + "&tt=" + tt + "&u=" + u + "&username=" + username
				+ "&verifycode=" + verifycode;
		content = "password=" + password +"&username=" + username;
		String result = HttpLoginService.getResult(urlStr, content);
		System.out.println(result);
		out.print(result);
		out.flush();
		out.close();
	}

}
